
// import oimo.common.Vec3;
// import oimo.dynamics.rigidbody.RigidBody;

import { JointConfig } from "./JointConfig";
import { Vec3 } from "../../../common/Vec3";
import { SpringDamper } from "./SpringDamper";
import { RotationalLimitMotor } from "./RotationalLimitMotor";
import { RigidBody } from "../../rigidbody/RigidBody";

/**
 * A universal joint config is used for constructions of universal joints.
 */
export class UniversalJointConfig extends JointConfig {
	/**
	 * The first body's local constraint axis.
	 */
	localAxis1: Vec3;

	/**
	 * The second body's local constraint axis.
	 */
	localAxis2: Vec3;

	/**
	 * The rotational spring and damper along the first body's constraint axis.
	 */
	springDamper1: SpringDamper;

	/**
	 * The rotational spring and damper along the second body's constraint axis.
	 */
	springDamper2: SpringDamper;

	/**
	 * The rotational limit and motor along the first body's constraint axis.
	 */
	limitMotor1: RotationalLimitMotor;

	/**
	 * The rotational limit and motor along the second body's constraint axis.
	 */
	limitMotor2: RotationalLimitMotor;

	/**
	 * Default constructor.
	 */
	constructor() {
		super();
		this.localAxis1 = new Vec3(1, 0, 0);
		this.localAxis2 = new Vec3(1, 0, 0);
		this.springDamper1 = new SpringDamper();
		this.springDamper2 = new SpringDamper();
		this.limitMotor1 = new RotationalLimitMotor();
		this.limitMotor2 = new RotationalLimitMotor();
	}

	/**
	 * Sets rigid bodies, local anchors from the world anchor `worldAnchor`, local axes
	 * from the world axes `worldAxis1` and `worldAxis2`, and returns `this`.
	 */
	public init(rigidBody1: RigidBody, rigidBody2: RigidBody, worldAnchor: Vec3, worldAxis1: Vec3, worldAxis2: Vec3): UniversalJointConfig {
		this._init(rigidBody1, rigidBody2, worldAnchor);
		rigidBody1.getLocalVectorTo(worldAxis1, this.localAxis1);
		rigidBody2.getLocalVectorTo(worldAxis2, this.localAxis2);
		return this;
	}

}
